/*
 * Copyright (c) Huawei Device Co., Ltd. 2025. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "se_hianalytics.h"
#include "loghelper.h"
#include <gtest/gtest.h>
#include <memory>

namespace OHOS {
namespace SE {
namespace TEST {
using namespace testing::ext;
using namespace OHOS::SE;

class SeHianalyticsTest : public testing::Test {
public:
    static void SetUpTestCase() {};
    static void TearDownTestCase() {};
    void SetUp();
    void TearDown();
};

void SeHianalyticsTest::SetUp()
{
    std::cout << " SetUp DerParserTest." << std::endl;
}

void SeHianalyticsTest::TearDown()
{
    std::cout << " TearDown DerParserTest." << std::endl;
}

std::string g_errorLog;
void TestLogCallback(
    const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *msg)
{
    g_errorLog = msg;
}

/**
 * @tc.name: SeEventLogTest001
 * @tc.desc: Test SeEventLog with empty string.
 * @tc.type: FUNC
 */
HWTEST_F(SeHianalyticsTest, SeEventLogTest001, TestSize.Level1)
{
    LOG_SetCallback(TestLogCallback);
    SeHiAnalytics::GetInstance().SeEventLog(LOG_BASE, LOG_DEFAULT_STR);
    EXPECT_TRUE(g_errorLog.find("nothing to write") == std::string::npos);
}

/**
 * @tc.name: SeEventLogTest002
 * @tc.desc: Test SeEventLog with 1024 string..
 * @tc.type: FUNC
 */
HWTEST_F(SeHianalyticsTest, SeEventLogTest002, TestSize.Level1)
{
    LOG_SetCallback(TestLogCallback);
    std::string str(1024, '0');
    SeHiAnalytics::GetInstance().SeEventLog(LOG_BASE, str);
    EXPECT_TRUE(g_errorLog.find("nothing to write") == std::string::npos);
}

/**
 * @tc.name: SeEventLogTest003
 * @tc.desc: Test SeEventLog with empty string.
 * @tc.type: FUNC
 */
HWTEST_F(SeHianalyticsTest, SeEventLogTest003, TestSize.Level1)
{
    LOG_SetCallback(TestLogCallback);
    SeHiAnalytics::GetInstance().SeEventLog(LOG_BASE, LOG_DEFAULT_STR, "1234");
    EXPECT_TRUE(g_errorLog.find("nothing to write") == std::string::npos);
}

/**
 * @tc.name: SeEventLogTest004
 * @tc.desc: Test SeEventLog with 1024 string..
 * @tc.type: FUNC
 */
HWTEST_F(SeHianalyticsTest, SeEventLogTest004, TestSize.Level1)
{
    LOG_SetCallback(TestLogCallback);
    std::string str(1024, '0');
    SeHiAnalytics::GetInstance().SeEventLog(LOG_BASE, str, "1234");
    EXPECT_TRUE(g_errorLog.find("nothing to write") == std::string::npos);
}

} // TEST
} // SE
} // OHOS